package spring.cloud.tasks.client.item_task_processor.pooled.timer_task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;


@Slf4j
public abstract class TimerTask implements Runnable {

    private String type;
    private String name;

    public TimerTask(String type, String name) {
        this.type = type;
        this.name = name;
    }


    @Override
    public void run() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        try {
            this.process();
        } catch (Throwable e) {
            log.error(this.type + this.name, e);
        } finally {
            stopWatch.stop();
            log.info("{}:{} 执行完成,耗时:{}ms", this.type + this.name, stopWatch.getTotalTimeMillis());
        }
    }

    /**
     * 定时任务逻辑
     */
    public abstract void process() throws Exception;
}
